package com.fiberhome.ztelauncher.core.page.holder;


import android.support.v7.widget.RecyclerView;
import android.util.SparseArray;
import android.view.View;

import com.fiberhome.ztelauncher.core.page.MultiTypeAdapter;
import com.fiberhome.ztelauncher.core.page.model.BaseType;
import com.fiberhome.ztelauncher.uilib.recycler.SpannableGridLayoutManager;


/**
 * Created by xc on 2018/3/27.
 */

public abstract class BaseViewHolder<T> extends RecyclerView.ViewHolder {
    private SparseArray<View> views;
    private View mItemView;

    public BaseViewHolder(View itemView) {
        super(itemView);
        views = new SparseArray<>();
        this.mItemView = itemView;
    }

    public View getView(int resID) {
        View view = views.get(resID);

        if (view == null) {
            view = mItemView.findViewById(resID);
            views.put(resID,view);
        }

        return view;
    }

    public void setItemViewParams(BaseType baseType) {
        SpannableGridLayoutManager.LayoutParams params = (SpannableGridLayoutManager.LayoutParams) itemView.
                getLayoutParams();
        params.colSpan = baseType.getLayoutElement().width;
        params.rowSpan = baseType.getLayoutElement().height;
        itemView.setLayoutParams(params);
    }

    public abstract void setUpView(T model, int position, MultiTypeAdapter adapter);

    public interface OnFocusListener{
        void onFocus(BaseViewHolder baseViewHolder,boolean isFocus,int position);
    }
}
